package at.fhj.itm10.ticketmaster.helper;

/**
 * Validation helper class.
 * 
 * @author Wolfgang Gaar
 */
public class Validator {

	private Validator() {
		// stub
	}
	
	/**
	 * Checks wether an Object is not null
	 * 
	 * @param object
	 * @return boolean
	 */
	public static boolean isNotNull(Object object) {
		return object != null;
	}
	
	/**
	 * Checks wether an Object is null
	 * 
	 * @param object
	 * @return boolean
	 */
	public static boolean isNull(Object object) {
		return !isNotNull(object);
	}

	/**
	 * Throw exception if object is null. message may be null.
	 * 
	 * @param object
	 * @param message
	 */
	public static void notNullOrThrow(Object object, String message) {
		if (isNull(object)) {
			if (message == null) {
				throw new RuntimeException();
			}
			
			throw new RuntimeException(message);
		}
	}
	
	/**
	 * Check wether a number is zero
	 * 
	 * @param number
	 * @return boolean
	 */
	public static boolean isZero(long number) {
		return number == 0;
	}
	
	/**
	 * Throw exception if number is not zero. message may be null.
	 * 
	 * @param number
	 * @param message
	 */
	public static void zeroOrThrow(long number, String message) {
		if (!isZero(number)) {
			if (message == null) {
				throw new RuntimeException();
			}
			
			throw new RuntimeException(message);
		}
	}

	/**
	 * Throw exception if number is zero. message may be null.
	 * 
	 * @param number
	 * @param message
	 */
	public static void notZeroOrThrow(long number, String message) {
		if (isZero(number)) {
			if (message == null) {
				throw new RuntimeException();
			}
			
			throw new RuntimeException(message);
		}
	}
}
